package ${modulePackage}.criteria;

import cn.hutool.core.collection.CollUtil;
import lombok.Setter;
import cn.jimjim.framework.code.generator.common.AbstractCriteria;
import ${modulePackage}.model.${className};
import java.util.Set;
import java.math.BigDecimal;

import static ${modulePackage}.jooq.Tables.${table?upper_case};

/**
* @author ${userName}
*/
@Setter
public class ${className}Criteria extends AbstractCriteria<${className}> {
<#list fields as field>

    /************************************************** ${field.fieldName} **************************************************/

    private ${field.fieldTypeName} ${field.fieldName};

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)};

    private Set<${field.fieldTypeName}> ${field.fieldName}In;

    private Set<${field.fieldTypeName}> or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In;

    private Set<${field.fieldTypeName}> ${field.fieldName}NotIn;

    private Set<${field.fieldTypeName}> or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn;

<#if field.fieldTypeName == "String">
    private ${field.fieldTypeName} ${field.fieldName}Like;

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like;
        
    private ${field.fieldTypeName} ${field.fieldName}NotLike;

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike;

    private ${field.fieldTypeName} ${field.fieldName}StartWith;
    
    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}StartWith;    
</#if>
<#if field.fieldTypeName == "Integer" || field.fieldTypeName == "Long" || field.fieldTypeName == "Date" || field.fieldTypeName == "BigDecimal">
    private ${field.fieldTypeName} ${field.fieldName}NotEqual;

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotEqual;

    private ${field.fieldTypeName} ${field.fieldName}LessThan;

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan;

    private ${field.fieldTypeName} ${field.fieldName}LessThanEqual;

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual;

    private ${field.fieldTypeName} ${field.fieldName}GreaterThan;

    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan;

    private ${field.fieldTypeName} ${field.fieldName}GreaterThanEqual;
        
    private ${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual;

</#if>
</#list>
<#list fields as field>

    /************************************************** ${field.fieldName} **************************************************/

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}(${field.fieldTypeName} ${field.fieldName}) {
        this.${field.fieldName} = ${field.fieldName};
        equal(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName});
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}) {
        this.${field.fieldName} = ${field.fieldName};
        orEqual(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName});
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In(Set<${field.fieldTypeName}> ${field.fieldName}In) {
        this.${field.fieldName}In = ${field.fieldName}In;
        in(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}In);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In(Set<${field.fieldTypeName}> or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In;
        orIn(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn(Set<${field.fieldTypeName}> ${field.fieldName}NotIn) {
        this.${field.fieldName}NotIn = ${field.fieldName}NotIn;
        notIn(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}NotIn);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn(Set<${field.fieldTypeName}> or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn;
        orNotIn(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In(${field.fieldTypeName}... ${field.fieldName}In) {
        this.${field.fieldName}In = CollUtil.newHashSet(${field.fieldName}In);
        in(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}In);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In(${field.fieldTypeName}... or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In = CollUtil.newHashSet(or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In);
        orIn(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}In);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn(${field.fieldTypeName}... ${field.fieldName}NotIn) {
        this.${field.fieldName}NotIn = CollUtil.newHashSet(${field.fieldName}NotIn);
        notIn(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}NotIn);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn(${field.fieldTypeName}... or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn = CollUtil.newHashSet(or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn);
        orNotIn(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotIn);
        return this;
    }
    
<#if field.fieldTypeName == "String">
    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like(${field.fieldTypeName} ${field.fieldName}Like) {
        this.${field.fieldName}Like = ${field.fieldName}Like == null ? null : ${field.fieldName}Like.trim();
        like(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}Like);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like == null ? null : or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like.trim();
        orLike(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}Like);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike(${field.fieldTypeName} ${field.fieldName}NotLike) {
        this.${field.fieldName}NotLike = ${field.fieldName}NotLike == null ? null : ${field.fieldName}NotLike.trim();
        notLike(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}NotLike);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike == null ? null : or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike.trim();
        orNotLike(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}NotLike);
        return this;
    }

</#if>
<#if field.fieldTypeName == "Integer" || field.fieldTypeName == "Long" || field.fieldTypeName == "Date" || field.fieldTypeName == "BigDecimal">

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan(${field.fieldTypeName} ${field.fieldName}LessThan) {
        this.${field.fieldName}LessThan = ${field.fieldName}LessThan;
        lessThan(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}LessThan);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan;
        orLessThan(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThan);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual(${field.fieldTypeName} ${field.fieldName}LessThanEqual) {
        this.${field.fieldName}LessThanEqual = ${field.fieldName}LessThanEqual;
        lessThanEqual(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}LessThanEqual);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual;
        orLessThanEqual(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}LessThanEqual);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan(${field.fieldTypeName} ${field.fieldName}GreaterThan) {
        this.${field.fieldName}GreaterThan = ${field.fieldName}GreaterThan;
        greaterThan(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}GreaterThan);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan;
        orGreaterThan(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThan);
        return this;
    }

    public ${className}Criteria set${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual(${field.fieldTypeName} ${field.fieldName}GreaterThanEqual) {
        this.${field.fieldName}GreaterThanEqual = ${field.fieldName}GreaterThanEqual;
        greaterThanEqual(${table?upper_case}.${field.columnName?upper_case}, this.${field.fieldName}GreaterThanEqual);
        return this;
    }

    public ${className}Criteria setOr${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual(${field.fieldTypeName} or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual) {
        this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual = or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual;
        orGreaterThanEqual(${table?upper_case}.${field.columnName?upper_case}, this.or${field.fieldName?substring(0,1)?upper_case}${field.fieldName?substring(1)}GreaterThanEqual);
        return this;
    }
</#if>
</#list>


}
